package com.nova.bluetooth.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;

import com.nova.bluetooth.helpUtils.LogUtil;

public class MyMediaButtonReceiver  extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
            if (event != null) {
                int action = event.getAction();
                int keyCode = event.getKeyCode();
                if (action == KeyEvent.ACTION_DOWN) {
                    switch (keyCode) {
                        case KeyEvent.KEYCODE_MEDIA_PLAY:
                            Log.d("MyMediaButtonReceiver", "Media Play");
                            // 处理播放事件
                            break;
                        case KeyEvent.KEYCODE_MEDIA_PAUSE:
                            Log.d("MyMediaButtonReceiver", "Media Pause");
                            // 处理暂停事件
                            break;
                        case KeyEvent.KEYCODE_MEDIA_NEXT:
                            Log.d("MyMediaButtonReceiver", "Media Next");
                            // 处理下一首事件
                            break;
                        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                            Log.d("MyMediaButtonReceiver", "Media Previous");
                            // 处理上一首事件
                            break;
                    }
                }
            }
        }
    }

    private void wakeUpApp(Context context) {
        LogUtil.d("test===>接收到按键功能广播");
//        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(
//                context.getPackageName());
//        if (launchIntent != null) {
//            launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            context.startActivity(launchIntent);
//        }
    }
}
